//
//  SDPVCForUser.m
//  BreadTrip
//
//  Created by sp on 16/2/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ControllerViewForDenglu.h"



@interface ControllerViewForDenglu ()

@end

@implementation ControllerViewForDenglu
- (void)dealloc {
    
    [super dealloc];
}
- (void)viewWillAppear:(BOOL)animated{
    
    self.view.backgroundColor = RGBA(49, 211, 209, 1);
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creaeSubView];
}


#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
- (void)creaeSubView{
    
    // 取消键
    
    UIButton *buttonForDelete = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForDelete.backgroundColor = [UIColor clearColor];
    buttonForDelete.frame = CGRectMake(WIDTH / 40, WIDTH / 12, WIDTH / 10, WIDTH / 10);
    [buttonForDelete setImage:[UIImage imageNamed:@"iconfont-fanhui(baise)"] forState:UIControlStateNormal];
    [self.view addSubview:buttonForDelete];
    
    [buttonForDelete addTarget:self action:@selector(BackRootVc:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *labelForTittle = [[UILabel alloc] init];
    labelForTittle.backgroundColor = [UIColor clearColor];
    labelForTittle.frame = CGRectMake(WIDTH / 10, WIDTH / 4, WIDTH - WIDTH / 10 * 2, WIDTH / 5);
    labelForTittle.text = @"你好,  面粉!";
    labelForTittle.textColor = [UIColor whiteColor];
    labelForTittle.textAlignment = NSTextAlignmentCenter;
    labelForTittle.font = [UIFont systemFontOfSize:30];
    [self.view addSubview:labelForTittle];
    [labelForTittle release];
    
    UIButton *buttonForWechat = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForWechat.backgroundColor = [UIColor clearColor];
    buttonForWechat.frame = CGRectMake(WIDTH / 10, WIDTH / 2, WIDTH / 8, WIDTH / 8);
    [self.view addSubview:buttonForWechat];
    [buttonForWechat setBackgroundImage:[UIImage imageNamed:@"iconfont-weixin"] forState:UIControlStateNormal];
    
    UIButton *buttonForWeiBo = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForWeiBo.backgroundColor = [UIColor clearColor];
    buttonForWeiBo.frame = CGRectMake(WIDTH / 2.3, WIDTH / 2, WIDTH / 8, WIDTH / 8);
    [self.view addSubview:buttonForWeiBo];
    [buttonForWeiBo setBackgroundImage:[UIImage imageNamed:@"iconfont-weibo"] forState:UIControlStateNormal];
    [buttonForWeiBo addTarget:self action:@selector(buttonForWeiboAction:) forControlEvents:UIControlEventTouchUpInside];
    UIButton *buttonForQQ = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonForQQ.backgroundColor = [UIColor clearColor];
    buttonForQQ.frame = CGRectMake(WIDTH / 1.3, WIDTH / 2, WIDTH / 8, WIDTH / 8);
    [self.view addSubview:buttonForQQ];
    [buttonForQQ setBackgroundImage:[UIImage imageNamed:@"iconfont-qq"] forState:UIControlStateNormal];
    [buttonForQQ addTarget:self action:@selector(buttonForQQAction:) forControlEvents:UIControlEventTouchUpInside];
  // 竖线
    
    UIView *viewForLine1 = [[UIView alloc] init];
    viewForLine1.backgroundColor = [UIColor whiteColor];
    viewForLine1.frame = CGRectMake(WIDTH / 3, WIDTH / 1.95, WIDTH / 600, WIDTH / 10);
    viewForLine1.alpha = 0.5;
    [self.view addSubview:viewForLine1];
    [viewForLine1 release];
    
    UIView *viewForLine2 = [[UIView alloc] init];
    viewForLine2.backgroundColor = [UIColor whiteColor];
    viewForLine2.frame = CGRectMake(WIDTH / 1.5, WIDTH / 1.95, WIDTH / 600, WIDTH / 10);
    viewForLine2.alpha = 0.5;
    [self.view addSubview:viewForLine2];
    [viewForLine2 release];
    
    
    UIButton *buttonForMore = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonForMore.backgroundColor = [UIColor clearColor];
    buttonForMore.frame = CGRectMake(WIDTH / 3, WIDTH / 1.4, WIDTH - WIDTH / 3 * 2, WIDTH / 10);
    buttonForMore.layer.cornerRadius = WIDTH / 20;
    buttonForMore.layer.masksToBounds = 3;
    //边
    buttonForMore.layer.borderWidth = 0.4;
    buttonForMore.layer.borderColor = [UIColor whiteColor].CGColor;
    [buttonForMore setTitle:@"更多社交平台" forState:UIControlStateNormal];
    // 按键颜色
    [buttonForMore setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [buttonForMore.titleLabel setFont:[UIFont systemFontOfSize:15]];
    //缩进10个距离以免紧贴着button边缘
    buttonForMore.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
    [self.view addSubview:buttonForMore];
    
    
    
    
    UIButton *buttonForPhoneNum = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonForPhoneNum.backgroundColor = [UIColor whiteColor];
    buttonForPhoneNum.frame = CGRectMake(WIDTH / 8, WIDTH / 0.9, WIDTH - WIDTH / 8 * 2, WIDTH / 10);
   buttonForPhoneNum.layer.cornerRadius = WIDTH / 20;
   buttonForPhoneNum.layer.masksToBounds = 3;
    //边
    buttonForPhoneNum.layer.borderWidth = 0.6;
    buttonForPhoneNum.layer.borderColor = [UIColor whiteColor].CGColor;
    [buttonForPhoneNum setTitle:@"通过手机号码登录" forState:UIControlStateNormal];
    // 按键颜色
    [buttonForPhoneNum setTitleColor:[UIColor colorWithRed:0.f green:192/255.f blue:203/255.f alpha:1]forState:UIControlStateNormal];
    [buttonForPhoneNum.titleLabel setFont:[UIFont systemFontOfSize:15]];
    //缩进10个距离以免紧贴着button边缘
    buttonForPhoneNum.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
    [self.view addSubview:buttonForPhoneNum];
    
    
    UIButton *buttonForEmail = [UIButton buttonWithType:UIButtonTypeSystem];
   buttonForEmail.backgroundColor = [UIColor clearColor];
   buttonForEmail.frame = CGRectMake(WIDTH / 8, WIDTH / 0.8, WIDTH - WIDTH / 8 * 2, WIDTH / 10);
    buttonForEmail.layer.cornerRadius = WIDTH / 20;
    buttonForEmail.layer.masksToBounds = 3;
    //边
    buttonForEmail.layer.borderWidth = 0.6;
    buttonForEmail.layer.borderColor = [UIColor whiteColor].CGColor;
    [buttonForEmail setTitle:@"面包用户名或邮箱登录" forState:UIControlStateNormal];
    // 按键颜色
    [buttonForEmail setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [buttonForEmail.titleLabel setFont:[UIFont systemFontOfSize:15]];
    //缩进10个距离以免紧贴着button边缘
    buttonForEmail.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
    [self.view addSubview:buttonForEmail];
    
    //面包账户的 line
    UIView *viewForLine = [[UIView alloc] init];
    viewForLine.backgroundColor = [UIColor whiteColor];
    viewForLine.frame = CGRectMake(WIDTH / 8, WIDTH / 1.01, WIDTH - WIDTH / 8 * 2, WIDTH / 600);
    [self.view addSubview:viewForLine];
    [viewForLine release];
    
    //底下的 line
    UIView *viewForBoottomLine = [[UIView alloc] init];
    viewForBoottomLine.backgroundColor = [UIColor whiteColor];
    viewForBoottomLine.frame = CGRectMake(0, HEIGHT - WIDTH / 7, WIDTH , WIDTH / 600);
    [self.view addSubview:viewForBoottomLine];
    [viewForBoottomLine release];
    
    
    UILabel *labelForAcount = [[UILabel alloc] init];
    labelForAcount.backgroundColor = [UIColor colorWithRed:0.f green:192/255.f blue:203/255.f alpha:1];
    
    labelForAcount.frame = CGRectMake(WIDTH / 3.5, WIDTH / 1.04, WIDTH - (WIDTH / 3.5 * 2), WIDTH / 20);
    labelForAcount.text = @"使用面包账号登录";
    labelForAcount.textColor = [UIColor whiteColor];
    labelForAcount.textAlignment = NSTextAlignmentCenter;
    labelForAcount.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:labelForAcount];
    [labelForAcount release];
    
    
    // 竖线
    
    UIView *viewForLine3 = [[UIView alloc] init];
    viewForLine3.backgroundColor = [UIColor whiteColor];
    viewForLine3.frame = CGRectMake(WIDTH / 2, HEIGHT - WIDTH / 7, WIDTH / 600, WIDTH / 10);
    viewForLine3.alpha = 1;
    [self.view addSubview:viewForLine3];
    [viewForLine3 release];
    
    // 忘记密码
    UIButton *buttonForKey = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonForKey.backgroundColor = [UIColor clearColor];
    buttonForKey.frame = CGRectMake(0, HEIGHT - WIDTH / 8, WIDTH / 2, WIDTH / 10);
    [buttonForKey setTitle:@"忘记密码" forState:UIControlStateNormal];
    
    // 按键颜色
    [buttonForKey setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [buttonForKey.titleLabel setFont:[UIFont systemFontOfSize:15]];
    //缩进10个距离以免紧贴着button边缘
    buttonForMore.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self.view addSubview:buttonForKey];
    
    
    //注册账号
    UIButton *buttonForregistration = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonForregistration.backgroundColor = [UIColor clearColor];
    buttonForregistration.frame = CGRectMake(WIDTH / 2, HEIGHT - WIDTH / 8, WIDTH / 2, WIDTH / 10);
    [buttonForregistration setTitle:@"注册账号" forState:UIControlStateNormal];
    
    // 按键颜色
    [buttonForregistration setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [buttonForregistration.titleLabel setFont:[UIFont systemFontOfSize:15]];
    //缩进10个距离以免紧贴着button边缘
    buttonForregistration.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
    [self.view addSubview:buttonForregistration];
    

}
- (void)buttonForQQAction:(UIButton *)button {
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:snsAccount.userName forKey:@"name"];
            [dic setObject:snsAccount.iconURL forKey:@"iconURL"];
            [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"登录"];
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
        }});
}
- (void)buttonForWeiboAction:(UIButton *)button {
    
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:snsAccount.userName forKey:@"name"];
            [dic setObject:snsAccount.iconURL forKey:@"iconURL"];
            [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"登录"];
            NSLog(@"%@", NSHomeDirectory());
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
//            //把数据写在本地沙盒中
//            NSString *stringPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
//            NSString *userNamePath = [stringPath stringByAppendingPathComponent:@"userName.text"];
//            [userName writeToFile:userNamePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
//            NSString *userPicPath = [stringPath stringByAppendingPathComponent:@"userPic.text"];
//            [picUrl writeToFile:userPicPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
//            NSLog(@"~~~~~%@",userNamePath);
//            NSLog(@"!!!!!!%@",userPicPath);
        }});
    
    
    
    //获取accestoken以及新浪用户信息，得到的数据在回调Block对象形参respone的data属性
    [[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"SnsInformation is %@",response.data);
    }];
    
    [[UMSocialDataService defaultDataService] requestSnsFriends:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"SnsFriends is %@",response.data);
    }];
    
    [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"response is %@",response);
    }];

    
    // 删除授权
    [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"response is %@",response);
    }];
    
}

// 跳转回主页面
- (void)BackRootVc:(UIButton *)button{
    //NSLog(@"%@", self.text);

    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
